package club.janna.concurrency.example.threadPool;

import lombok.extern.slf4j.Slf4j;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@Slf4j
public class ThreadPoolExample4 {
    public static void main(String[] args) {
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(3);
        executorService.schedule(() -> {
            log.info("task is running");
        }, 1, TimeUnit.SECONDS);

        executorService.scheduleAtFixedRate(() -> {
            log.info("task is running1");
        }, 1, 2, TimeUnit.SECONDS);
        executorService.shutdown();

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                log.info("timer is running");
            }
        }, 1 * 1000, 2 * 1000);
        //timer.cancel();
    }
}
